package org.dizena.base.shiro;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;
import org.dizena.base.enums.Constant;
import org.dizena.modules.master.bean.User;

public class SessionUserUtil
{

    public static User getSessionUser()
    {
        Subject subject = SecurityUtils.getSubject();
        if (subject != null)
        {
            Session session = subject.getSession();
            if (session != null)
            {
                Object obj = session.getAttribute(Constant.CurrentUser);
                if (obj instanceof User)
                {
                    return (User) obj;
                }
            }

        }
        return null;
    }

    public static Session getSession()
    {
        Subject subject = SecurityUtils.getSubject();
        return subject.getSession();
    }

    public static String getSid()
    {
        Subject subject = SecurityUtils.getSubject();
        return subject.getSession().getId().toString();
    }

    public static Boolean checkRole(String role)
    {
        Subject subject = SecurityUtils.getSubject();
        return subject.hasRole(role);
    }


}
